package com.rub.android.ui.activity

import android.os.Bundle
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.rub.android.R

/**
 * https://www.jianshu.com/p/791ee473a89b
 */
class GlideImageActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_glide_image)
        val glideIv: ImageView = this.findViewById(R.id.glide_iv_target)
        //val url = "http://cn.bing.com/az/hprichbg/rb/TOAD_ZH-CN7336795473_1920x1080.jpg"
        val url = "https://bestanimations.com/Fantasy/creatures/animated-phoenix-flame.gif"
        Glide.with(this)
            .load(url)
            //图片加载出来前，显示的图片
            .placeholder(R.drawable.ic_baseline_preview_24)
            //图片加载失败后，显示的图片
            .error(R.drawable.ic_baseline_error_24)
            .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
            .into(glideIv)

    }
}